package com.poi;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileInputStream;

/**
 * @author Macrydy
 * @date 2023/4/27
 */
public class ReadDemo {
    public static void main(String[] args) throws Exception{
        read03();
    }
    //03版读取
    public static void read03() throws Exception {
        //获取文件输入流
        FileInputStream fileInputStream = new FileInputStream("excel03.xls");
        //获取工作簿
        Workbook workbook = new HSSFWorkbook(fileInputStream);
        //获取sheet页
        Sheet sheet = workbook.getSheetAt(0);
        //获取行
        Row row = sheet.getRow(0);
        //获取单元格
        Cell cell = row.getCell(0);
        //获取单元格中的值
        String value = cell.getStringCellValue();

        System.out.println(value);
    }

    //03版批量读取
    public static void readBatch03() throws Exception {
        //获取文件输入流
        FileInputStream fileInputStream = new FileInputStream("excel03.xls");
        //获取工作簿
        Workbook workbook = new HSSFWorkbook(fileInputStream);
        //获取sheet页
        Sheet sheet = workbook.getSheetAt(0);
        //获取行
        Row row = sheet.getRow(0);
        //获取单元格
        Cell cell = row.getCell(0);
        //获取单元格中的值
        String value = cell.getStringCellValue();

        System.out.println(value);
    }

}
